<?php
require_once('data/SugarBean.php');
class JsFileGenerator {
	//generate workload unit js file
	function JsFileGenerator(&$bean, $event, $arguments){
		
		$filePath="custom/modules/edanz_Workload_unit/javascript/";
		$fileName="edanzWorkloadUnit.js";
		$file_content="var edanzWorloadUnitPointsDict = {";
		$workload_units= $bean->get_full_list("","");
		if ( $workload_units!= null ) {
			$count = 0;
			foreach ($workload_units as $workload_unit) {
				$type = $workload_unit->tasktype;
				$unit= $workload_unit->unit;
				$point = $workload_unit->point;
				$description = $workload_unit->description;
				$feeJson="";
				if(count($units)-1!=$count){
					$feeJson=$type.':  { name : "'.$type.'", unit :"'.$unit.'", point :"'.$point.'", description :"'.$description.'"},';                    
				}else{
					
					$feeJson=$type.':  { name : "'.$type.'", unit :"'.$unit.'", point :"'.$point.'", description :"'.$description.'"}';                    
				}
				$file_content.="\r\n".$feeJson;
				$count++;

			}
		}
		$file_content.="\r\n"."};";
		$file = fopen($filePath.$fileName, 'w') or die('Could not open file.');
		fwrite($file, $file_content) or die('Could not write to file.');
		fclose($file);

   		
	}

}



?>
